
getNum = function(position) {
    var size=0, total=0, total0=0;
    while(total<position) {
        //1: 1-9
        //2: 10-99
        //3: 100-999
        //4: 1000-9999
        total0 = total;
        size++
        total += size* ((Math.pow(10,size) - Math.pow(10,size-1)))
    }
    
    //print(size + "....");
    tmp0 = (position-total0)/size;
    tmp1 = (position-total0)%size;
    print("total=" + total +",total0=" + total0);
    print("pos=" + position +",size=" + size+",tmp0=" + tmp0 + ",tmp1=" + tmp1);
    //print((Math.pow(10, size-1)+tmp0).toString());
    if(tmp1==0) return (Math.pow(10, size-1)+tmp0-1).toString().substr(size-1,1);
    return (Math.pow(10, size-1)+tmp0).toString().substr(tmp1-1,1);
}

print(getNum(1));
print(getNum(10));
print(getNum(100));
print(getNum(1000));
print(getNum(10000));
print(getNum(100000));
print(getNum(1000000));


